home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ipgrab1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-08-31  |  3.6 KB  |  103 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   1350
  5.    ClientLeft      =   3930
  6.    ClientTop       =   2865
  7.    ClientWidth     =   3045
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   90
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   203
  12.    Begin VB.CommandButton Command2 
  13.       Caption         =   "Quit"
  14.       Height          =   375
  15.       Left            =   2160
  16.       TabIndex        =   2
  17.       Top             =   120
  18.       Width           =   735
  19.    End
  20.    Begin VB.CommandButton Command1 
  21.       Caption         =   "Get my IP Address"
  22.       Height          =   375
  23.       Left            =   120
  24.       TabIndex        =   0
  25.       Top             =   120
  26.       Width           =   1815
  27.    End
  28.    Begin VB.Label Label1 
  29.       Alignment       =   2  'Center
  30.       BorderStyle     =   1  'Fixed Single
  31.       Caption         =   "Label1"
  32.       Height          =   255
  33.       Left            =   360
  34.       TabIndex        =   1
  35.       Top             =   720
  36.       Width           =   2295
  37.    End
  38. Attribute VB_Name = "Form1"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Option Explicit
  44. 'Required functions neccessary for our custom CloseApp subroutine.
  45. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer
  46. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  47. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  48. Private Sub Command1_Click()
  49. Dim dummylong As Long
  50. Dim mystring As String
  51. Dim pos As Integer
  52. 'We need to run the winipcfg proggie.
  53.     dummylong = Shell("winipcfg.exe", 2)
  54.     AppActivate dummylong
  55.     DoEvents
  56. 'Copy the info to the Clipboard.
  57.     SendKeys "^+C", True
  58.     DoEvents
  59. 'Now close the winifcfg proggie by calling our custom subroutine.
  60.     Call CloseApp
  61. 'Load the copied info from the Clipboard to our string.
  62.     mystring = Clipboard.GetText()
  63. 'Extract the desired info from the string.
  64.     pos = InStr(mystring, "IP Address")
  65.     mystring = Right$(mystring, Len(mystring) - (pos - 1))
  66.     pos = InStr(mystring, vbCrLf)
  67.     mystring = Left$(mystring, (pos - 1))
  68.     pos = InStr(mystring, ":")
  69.     mystring = Right$(mystring, Len(mystring) - (pos + 1))
  70. 'Finally, display the desired info (our IP Address) in our label.
  71.     Label1.Caption = mystring
  72. End Sub
  73. Public Sub CloseApp()
  74. 'This sub will search out the task list for the WINIFCFG program,
  75. 'and will close it down.
  76. Dim CurrWind&
  77. Dim ret&
  78. Dim dummylong&
  79. Dim dummy%
  80. Const GW_HWNDFIRST = 0
  81. Const GW_HWNDNEXT = 2
  82. Const WM_CLOSE = &H10
  83. Dim WindowText$
  84. WindowText$ = Space$(100)
  85. 'Get the hWnd of the first item in the master list so we can process
  86. 'the task list entries (top-level only).
  87. CurrWind& = GetWindow(Form1.hwnd, GW_HWNDFIRST)
  88. 'Loop while the returned handle is valid.
  89. While CurrWind& <> 0
  90.         'Get the Window text of the handle we're looking at.
  91.         ret& = GetWindowText(CurrWind&, WindowText$, 100)
  92.         If Left(WindowText$, 16) = "IP Configuration" Then
  93.             dummylong& = SendMessage(CurrWind&, WM_CLOSE, 0, 0)
  94.             dummy% = DoEvents()
  95.             Exit Sub
  96.         End If
  97.         CurrWind& = GetWindow(CurrWind&, GW_HWNDNEXT)
  98.         dummy% = DoEvents()
  99. End Sub
  100. Private Sub Command2_Click()
  101.     End
  102. End Sub
  103.